package com.topboya.linker.ui.adapter;

import android.widget.CheckBox;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.topboya.linker.R;
import com.topboya.linker.model.levelitem.DepartmentGroupBo;
import com.topboya.linker.model.response.TencentLocationResponse;
import com.topboya.linker.utils.LogUtils;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


public class xDeptUserAdapter extends BaseQuickAdapter<DepartmentGroupBo, BaseViewHolder> {

    private static final String TAG = "DeptUserAdapter:";

    private LinkedHashMap<String ,DepartmentGroupBo> selectedDepartLinkHashList = new LinkedHashMap<>();

    public xDeptUserAdapter(List<DepartmentGroupBo> departmentGroups) {

        super(R.layout.select_team_item, departmentGroups);
}

   public  void setSelectDepartLinkHash(LinkedHashMap<String ,DepartmentGroupBo> selectedDepartLinkHashList){

       this.selectedDepartLinkHashList.clear();
       this.selectedDepartLinkHashList.putAll(selectedDepartLinkHashList);
       LogUtils.v(TAG +"entry----->"+selectedDepartLinkHashList.size());

   }

    @Override
    protected void convert(BaseViewHolder viewHolder,DepartmentGroupBo departmentGroup) {

         String  departname = departmentGroup.getDeparemtname();
         viewHolder.setText(R.id.tv_head_name,departname);
         viewHolder.setText(R.id.tv_head_num,"("+departmentGroup.getSelectedNum()+"/"+departmentGroup.getTotalnum()+")");
         LogUtils.v(TAG +"setChecked:"+selectedDepartLinkHashList.get(departmentGroup.getMemberID()));
        ((CheckBox)viewHolder.getView(R.id.ck_select)).setChecked(null==selectedDepartLinkHashList.get(departmentGroup.getMemberID()) ? false :true);
         viewHolder.addOnClickListener(R.id.ck_select);

        if (departmentGroup.isSub()){
            viewHolder.setGone(R.id.tv_head_pic,false);
            viewHolder.setGone(R.id.tv_head_num,true);

        }else {

            String  departnamepic = departname.substring(departname.length()-2);
            viewHolder.setGone(R.id.tv_head_pic,true);
            viewHolder.setGone(R.id.tv_head_num,false);
            viewHolder.setText(R.id.tv_head_pic,departnamepic);

        }
    }

}
